package main.chapter2

fun main(args: Array<String>) {
    for (arg in args) {
        println(arg)
    }

    for ((index, value) in args.withIndex()) {
        println("$index->$value")
    }

    for (indexAndValue in args.withIndex()) {
        println("${indexAndValue.index}->${indexAndValue.value}")
    }

    val list = MyIntList()
    list.add(1)
    list.add(2)
    list.add(3)
    for (i in list) {
        println(i)
    }

    var x = 6
    while (x > 0) {
        println(x--)
        if (x == 3) break
    }
    do {
        if (x == 4) {
            x++
            continue
        }
        println(x++)
    } while (x < 6)

    Outer@ for (i in 10..20) {
        var j = i
        Inner@ while (j > 0) {
            if (j == 15) {
                break@Outer
            }
            println(j--)
        }
    }
}

class MyIterator(val iterator: Iterator<Int>) {
    operator fun next(): Int {
        return iterator.next()
    }

    operator fun hasNext(): Boolean {
        return iterator.hasNext()
    }
}

class MyIntList {
    private val list = ArrayList<Int>()

    fun add(int: Int) {
        list.add(int)
    }

    fun remove(int: Int) {
        list.remove(int)
    }

    operator fun iterator(): MyIterator {
        return MyIterator(list.iterator())
    }
}